package com.sfzd5.exam.helplibrary.exam.answersheet;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * 论述题
 */
public class ExpoundAnswerSheetQuestion extends AnswerSheetQuestion {
    public ExpoundAnswerSheetQuestion(){
        areaType = Area.AreaType.Expound;
    }
    public ExpoundAnswerSheetQuestion(AnswerSheetQuestion answerSheetQuestion)
    {
        this.id = answerSheetQuestion.id;
        this.areaType = answerSheetQuestion.areaType;
        this.infoJson = answerSheetQuestion.infoJson;
        this.questionId = answerSheetQuestion.questionId;
        this.answer = answerSheetQuestion.answer;
        this.score = answerSheetQuestion.score;
    }
    private List<ExpoundChildQuestion> childQuestionList = null;

    public List<ExpoundChildQuestion> getChildQuestionList() {
        if(childQuestionList==null){
            if(infoJson!=null && !infoJson.isEmpty()){
                Type type = new TypeToken<ArrayList<ExpoundChildQuestion>>(){}.getType();
                childQuestionList = new Gson().fromJson(infoJson, type);
            } else {
                childQuestionList = new ArrayList<>();
            }
        }
        return childQuestionList;
    }

    public void setChildQuestionList(List<ExpoundChildQuestion> childQuestionList) {
        this.childQuestionList = childQuestionList;
        this.infoJson = new Gson().toJson(childQuestionList);
    }

    @Override
    public String toString() {
        return String.format("论述题");
    }
}
